package com.kujie.access.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kujie.access.domain.po.AccessCustomerServer;
import com.kujie.access.domain.query.CustomerServerQuery;
import com.kujie.access.domain.vo.CustomerServerVO;
import com.kujie.access.service.ICustomerServerService;
import com.kujie.common.core.domain.R;
import com.kujie.common.encrypt.annotation.ApiEncrypt;
import com.kujie.common.excel.utils.ExcelUtil;
import com.kujie.common.mybatis.core.page.PageQuery;
import com.kujie.common.web.core.BaseController;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 客户服务管理 controller
 *
 * @author check
 * @date 2025-06-30
 */
@Slf4j
@RestController
@RequestMapping("/customer/server")
@RequiredArgsConstructor
@ApiEncrypt(response = true)
public class CustomerServerController extends BaseController {
    private final ICustomerServerService customerServerService;


    @GetMapping("/list")
    public R<Page<CustomerServerVO>> list(CustomerServerQuery customerServerQuery, PageQuery pageQuery) {
        return R.ok(customerServerService.list(customerServerQuery, pageQuery));
    }

    @GetMapping("/detail")
    public R<CustomerServerVO> detail(Long id) {
        return R.ok(customerServerService.detail(id));
    }

    @PostMapping("/insertOrUpdate")
    public R<?> insertOrUpdate(@RequestBody AccessCustomerServer accessCustomerServer) {
        return toAjax(customerServerService.insertOrUpdate(accessCustomerServer));
    }

    @DeleteMapping("/delete/{ids}")
    public R<?> batchDelete(@PathVariable List<Long> ids) {
        return toAjax(customerServerService.batchDelete(ids));
    }

    @PostMapping("/batchExport")
    public void batchExport(@RequestBody CustomerServerQuery customerServerQuery, HttpServletResponse response) {
        List<CustomerServerVO> customerManagementVOS = customerServerService.batchExport(customerServerQuery, response);
        ExcelUtil.exportExcel(customerManagementVOS, "客户服务列表", CustomerServerVO.class, response);
    }

    @PostMapping("/batchImport")
    public R<?> batchImport(@RequestPart("file") MultipartFile file) throws Exception {
        return toAjax(customerServerService.batchImport(file));
    }

    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(CollectionUtil.newArrayList(), "客户服务列表导入模板", CustomerServerVO.class, response);
    }
}
